package org.xutils.xutillearn.model.modelImpl;

import android.nfc.Tag;
import android.util.Log;

import com.alibaba.fastjson.JSON;

import org.xutils.xutillearn.bean.LearnListItem;
import org.xutils.xutillearn.model.MainModel;
import org.xutils.xutillearn.uitls.CloseableUtil;
import org.xutils.xutillearn.uitls.LogUtils;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.List;

/**
 * Created by yangmuyi on 16/4/13.
 */
public class MainModelImpl implements MainModel {

    public static String TAG = MainModelImpl.class.getSimpleName();


    @Override
    public List<LearnListItem> getLearnItemList(InputStream inputStream){
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
        String str = null;
        try {
            int available = bufferedInputStream.available();
            byte[] bytes = new byte[available];
            bufferedInputStream.read(bytes);
            str = new String(bytes);
            LogUtils.printLog(TAG,"getLearnItemList str:"+str);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            CloseableUtil.close(inputStream);
        }
        List<LearnListItem> list = JSON.parseArray(str,LearnListItem.class);
        return list;
    }
}